export default {
  name: "chooseAddress",
  components: {
  },
  data() {
    return {
      itemData: [],
      page: 1,
      noData: false,
      noDataText: "已经拉到最底啦~",
      isLoad: false,
      addressId:""
    }

  },
  methods: {
    addAddress(){
      this.$router.push({
        path: '/address/add'
      })
    },
    dataInit(done) {
        this.$ajax.get('address/list', (res) => {
          // console.log(res)
          if (res.data) {
            this.itemData = this.page == 1 ? res.data : this.itemData.concat(res.data);
            this.page++;
          }

          if (typeof(done) == "function") {
            done();
          }
          if (this.$refs.selectAddScroller) {
            this.$refs.selectAddScroller.finishPullToRefresh(true);
          }
          if (!res.data || res.data.length < this.$rows) {
            this.noData = true;
            if (this.$refs.selectAddScroller) {
              this.$refs.selectAddScroller.finishInfinite(true);
            }
          }

        },{pageNo:this.page,pageSize:this.$rows})
    },
    refresh(done) {
      // console.log("refresh")
      this.isLoad = true;
      this.noData = false;
      this.itemData = []
      this.page = 1;
      this.dataInit(done);
    },

    infinite(done) {
      // console.log("infinite")
      if (!this.noData) {
        setTimeout(() => {
          if (this.isLoad) {
            this.$refs.selectAddScroller.finishInfinite(true);
            this.isLoad = false;
          } else {
            this.dataInit(done);
          }
        }, 800)

      } else {
        this.$refs.selectAddScroller.finishInfinite(true);
      }

    },
    selectInit(item){
      this.$storage.set('address',JSON.stringify(item))
      this.$router.go(-1);
      // if(this.$fromApp(this)){
      //   this.$router.replace({ path:'/cart/confirm',query:{address:JSON.stringify(item),sellerId:this.$route.query.sellerId,ids:this.$route.query.ids,from:'app'}})
      // }else{
      //   this.$router.replace({ path:'/cart/confirm',query:{address:JSON.stringify(item),sellerId:this.$route.query.sellerId,ids:this.$route.query.ids}})
      // }
    }
  },
  created() {
    // this.$changeTitle('选择地址');
  },
  mounted() {
      this.addressId=this.$route.query.addressId
  },

}
